# $OpenBSD: Makefile,v 1.23 2015/07/18 13:33:08 jca Exp $

SHARED_ONLY =		Yes
VERSION =		4.1.19
DISTNAME =		samba-${VERSION}
DOCSVERSION =		v3-5-test-4c5a1b6b
DISTFILES =		${DISTNAME}${EXTRACT_SUFX} \
			samba-docs-${DOCSVERSION}.tar.bz2:0

COMMENT-main =		SMB and CIFS client and server for UNIX
COMMENT-ldb =		LDAP-like embedded database
COMMENT-tevent =	event system based on talloc
COMMENT-util =		common libraries for Samba suite
COMMENT-docs =		additional documentation and examples for Samba

PKGNAME-main =		${PKGNAME}
PKGNAME-ldb =		ldb-${LDB_V}
PKGNAME-tevent =	tevent-${TEVENT_V}
PKGNAME-util =		samba-util-${VERSION}
PKGNAME-docs =		samba-docs-${VERSION}

REVISION-main =		3
REVISION-ldb =		3
REVISION-tevent =	1
REVISION-util =		1

PKG_ARCH-docs =		*

LDB_V =			1.1.17
TEVENT_V =		0.9.18

SHARED_LIBS =		asn1-samba4		0.0 \
			dcerpc			0.0 \
			dcerpc-atsvc		0.0 \
			dcerpc-binding		0.0 \
			dcerpc-samr		0.0 \
			dcerpc-server		0.0 \
			gensec			0.0 \
			gssapi-samba4		0.0 \
			hcrypto-samba4		0.0 \
			hdb-samba4		0.0 \
			heimbase-samba4		0.0 \
			heimntlm-samba4		0.0 \
			hx509-samba4		0.0 \
			kdc-samba4		0.0 \
			krb5-samba4		0.0 \
			ldb			0.0 \
			mit_samba		0.0 \
			ndr			0.0 \
			ndr-krb5pac		0.0 \
			ndr-nbt			0.0 \
			ndr-standard		0.0 \
			netapi			2.0 \
			ntdb			0.0 \
			pdb			0.0 \
			pyldb-util		0.0 \
			registry		0.0 \
			roken-samba4		0.0 \
			samba-credentials	0.0 \
			samba-hostconfig	0.0 \
			samba-policy		0.0 \
			samba-util		0.0 \
			samdb			0.0 \
			smbclient		4.0 \
			smbclient-raw		0.0 \
			smbconf			0.0 \
			smbldap			0.0 \
			smbsharemodes		2.0 \
			tevent			0.0 \
			tevent-util		0.0 \
			torture			0.0 \
			wbclient		2.0 \
			wind-samba4		0.0 \
			winbind_krb5_locator	0.0 \
			nss_wrapper		0.0 \
			socket_wrapper		0.0 \
			uid_wrapper		0.0 \
			replace			0.0 \
			util_setid		0.0

CATEGORIES =		net sysutils security

HOMEPAGE =		https://www.samba.org/

#MAINTAINER =		???

# GPLv3, LGPLv3
PERMIT_PACKAGE_CDROM =	Yes

UTIL_LIBS =		nss_wrapper socket_wrapper uid_wrapper replace
UTIL_LIBS +=		util_setid
# TODO WAF scripts link to those without version info, but those are
# not "plugins" or such.
UTIL_WANTLIB =		${UTIL_LIBS:S@^@lib/samba/@}

WANTLIB-common =	m pthread util ${MODPY_WANTLIB}

WANTLIB-main =		${WANTLIB-common} ${MODGETTEXT_WANTLIB}
WANTLIB-main +=		c com_err ncurses z
WANTLIB-main +=		avahi-client avahi-common cups execinfo fam iniparser
WANTLIB-main +=		lber ldap pam popt sasl2 gcrypt gnutls
WANTLIB-main +=		ldb pyldb-util pytalloc-util tdb talloc tevent
WANTLIB-main +=		${UTIL_WANTLIB}

WANTLIB-ldb =		${WANTLIB-common}
WANTLIB-ldb +=		c popt tdb talloc tevent
WANTLIB-ldb +=		${UTIL_WANTLIB}

WANTLIB-tevent =	${WANTLIB-common}
WANTLIB-tevent +=	talloc
WANTLIB-tevent +=	${UTIL_WANTLIB}

WANTLIB-util =		${WANTLIB-common}
WANTLIB-util +=		pytalloc-util talloc

WANTLIB-docs =

MASTER_SITES =		https://download.samba.org/pub/samba/stable/ \
			https://download.samba.org/pub/samba/old-versions/

MASTER_SITES0 =		https://www.samba.org/~samba-bugs/docs/v3-5-test/

MULTI_PACKAGES =	-main -ldb -tevent -util -docs

MODULES =		devel/gettext lang/python perl

BUILD_DEPENDS =		devel/p5-Parse-Yapp>=1.0.5 \
			net/py-dnspython \
			textproc/docbook-xsl \
			textproc/libxslt

RUN_DEPENDS-main =	net/py-dnspython

RUN_DEPENDS-docs =

LIB_DEPENDS-main =	${BUILD_PKGPATH},-ldb>=${LDB_V} \
			${BUILD_PKGPATH},-util>=${VERSION} \
			${MODGETTEXT_LIB_DEPENDS} \
			databases/openldap \
			databases/tdb>=1.2.12 \
			devel/iniparser \
			devel/libexecinfo \
			devel/libtalloc>=2.1.2 \
			net/avahi \
			print/cups,-libs \
			security/cyrus-sasl2 \
			security/gnutls \
			security/libgcrypt \
			security/openpam \
			sysutils/e2fsprogs \
			sysutils/gamin

LIB_DEPENDS-ldb =	${BUILD_PKGPATH},-tevent>=${TEVENT_V} \
			${BUILD_PKGPATH},-util>=${VERSION} \
			databases/tdb>=1.2.12 \
			devel/libtalloc>=2.1.2 \
			devel/popt

LIB_DEPENDS-tevent =	${BUILD_PKGPATH},-util>=${VERSION} \
			devel/libtalloc>=2.1.2

LIB_DEPENDS-util =	${MODPY_LIB_DEPENDS} \
			devel/libtalloc>=2.1.2

LIB_DEPENDS-docs =

CONFIGURE_STYLE =	simple

CONFIGURE_ARGS =	--enable-fhs \
			--abi-check-disable \
			--bundled-libraries="!crypto,ldb,ntdb,!talloc,!tdb,tevent" \
			--prefix=${PREFIX} \
			--destdir=${WRKINST} \
			--docdir=${PREFIX}/share/doc \
			--mandir=${PREFIX}/man \
			--localedir=${PREFIX}/share/locale \
			--localstatedir=${BASELOCALSTATEDIR} \
			--private-libraries="NONE" \
			--sharedstatedir=${VARBASE} \
			--sysconfdir=${SYSCONFDIR} \
			--with-configdir=${SYSCONFDIR}/samba \
			--with-statedir=${VARBASE}/samba \
			--with-privatedir=${VARBASE}/samba/private \
			--with-lockdir=${VARBASE}/run/samba \
			--with-privileged-socket-dir=${VARBASE}/samba \
			--without-pie \
			--enable-selftest \
			--pedantic \
			--without-regedit

# XXX Remember to remove --enable-developer, it prints passwords in logs.
#CONFIGURE_ARGS +=	--enable-developer

WAF =			${WRKSRC}/buildtools/bin/waf
WAF_ARGS =		-v -j ${MAKE_JOBS}

CONFIGURE_ENV =		LC_ALL=en_US.UTF-8

MAKE_ENV =		LC_ALL=en_US.UTF-8 \
			PYTHON=${MODPY_BIN} \
			WAF_ARGS="${WAF_ARGS}"

.for _l _v in ${SHARED_LIBS}
MAKE_ENV +=		LIB${_l:S/-/_/g}_VERSION=${_v}
.endfor

SAMBA_CONFIG =		${PREFIX}/share/examples/samba/smb.conf.default
SAMBA_LOGDIR =		${VARBASE}/log/samba

SUBST_VARS =		SAMBA_LOGDIR

post-patch:
	find ${WRKSRC} -type f | xargs ${MODPY_BIN_ADJ}
	${SUBST_CMD} ${WRKSRC}/lib/testtools/testtools/tests/test_compat.py

# Avoid bogus -L/usr/local/lib at the start of linker options
post-configure:
	perl -pi.ldflags -e 's/^LINKFLAGS_PYEMBED.*/LINKFLAGS_PYEMBED = []/' \
	    ${WRKBUILD}/bin/c4che/default.cache.py

post-install:
	# removing extra files
	find ${PREFIX} \
	    -name '*${PATCHORIG}' -or \
	    -name '*.beforesubst' -or \
	    -name '*.deconforig' | \
		xargs -rt rm --
	# fix path to perl modules
	mv ${PREFIX}/share/perl5/* ${PREFIX}/${P5SITE}
	# precompiling Python modules
	${MODPY_BIN} ${MODPY_LIBDIR}/compileall.py ${WRKINST}${MODPY_SITEPKG}
	${MODPY_BIN} -O ${MODPY_LIBDIR}/compileall.py ${WRKINST}${MODPY_SITEPKG}
	# creating library symlinks
.for _l in ${UTIL_LIBS}
	cd ${PREFIX}/lib && ln -fs samba/lib${_l}.so.${LIB${_l}_VERSION}
.endfor
	# install samba docs and sample config
	${INSTALL_DATA_DIR} ${PREFIX}/share/{doc,examples}/samba
	${INSTALL_DATA} ${WRKDIR}/samba-docs-${DOCSVERSION}/*.pdf \
		${PREFIX}/share/doc/samba
	cp -R ${WRKDIST}/examples/* ${PREFIX}/share/examples/samba
	chown -R ${SHAREOWN}:${SHAREGRP} ${PREFIX}/share/examples/samba
	find ${PREFIX}/share/examples/samba -type f | xargs chmod ${SHAREMODE}
	find ${PREFIX}/share/examples/samba -type d | xargs chmod ${DIRMODE}
	sed -e 's:/usr/spool/samba:/var/spool/samba:g' \
	     -e 's:/usr/local/samba/var/log:${SAMBA_LOGDIR}/smbd:g' \
	     -e 's:MYGROUP:WORKGROUP:' \
	     ${WRKDIST}/examples/smb.conf.default > ${SAMBA_CONFIG}.tmp && \
	    mv ${SAMBA_CONFIG}.tmp ${SAMBA_CONFIG}

.include <bsd.port.mk>
